﻿using System;
using System.Windows.Input;

namespace BabyCloudDrives.DesktopApp.ViewModels.Base
{
    public class ActionCommand : ICommand
    {
        private readonly Action _executeAction;
        private readonly Action<object> _executeActionByParam;

        public ActionCommand(Action action)
        {
            _executeAction = action;
        }

        public ActionCommand(Action<object> action)
        {
            _executeActionByParam = action;
        }

        public void Execute(object parameter)
        {
            if (_executeAction != null)
                _executeAction();
            if (_executeActionByParam != null)
                _executeActionByParam(parameter);
        }

        public bool CanExecute(object parameter)
        {
            return (_executeAction != null) || (_executeActionByParam != null);
        }

        public event EventHandler CanExecuteChanged
        {
            add { }
            remove { }
        }
    }
}